package com.mk3.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mk3.model.User;
import com.mk3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: peisong.chen
 * @Date: 2019/12/27 10:42
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping(value = "/insert")
    public Object insert(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @PostMapping(value = "/update")
    public Object update(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @PostMapping(value = "/delete")
    public Object delete(@RequestBody User user) {
        return userService.deleteUser(user);
    }

    @GetMapping(value = "/getUserByName")
    public Object getUserByName(@RequestParam String userName) {
        return userService.findUserByName(userName);
    }

    /**
     * 分页请求示例
     *
     * @return
     */
    @GetMapping(value = "/page")
    public Object getUserPage(Integer page,Integer size, String name) {
        Page pageReq = new Page();
        pageReq.setSize(size);
        pageReq.setCurrent(page);
        return userService.getUserPage(pageReq, name);
    }
}
